//
//  BLBaseViewController.m
//  Byelone
//
//  Created by 乔小乔 on 2020/12/14.
//

#import "BLBaseViewController.h"


@interface BLBaseViewController ()

@end

@implementation BLBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setLeftTitle:@"" imgShow:YES backImg:@"bar_back"];
}
- (void)setLeftTitle:(NSString *)title imgShow:(BOOL)isShow backImg:(NSString *)img{
    
    UIImage *backImg = [UIImage imageNamed:img];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tintColor =  [UIColor chColorWithHexString:@"#333333"];
    [button setTitleColor:[UIColor chColorWithHexString:@"#333333"] forState:UIControlStateNormal];
    UIFont *font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    button.titleLabel.font =font;
    
    NSDictionary *attributes = @{NSFontAttributeName: button.titleLabel.font};
    CGSize titleSize = [title  sizeWithAttributes:attributes];
    UIImage *image = nil;
    if(isShow){
        CGFloat titleWidth = titleSize.width == 0?40:titleSize.width;
        if (titleSize.width == 0) {
            [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        }else{
            [button setImageEdgeInsets:UIEdgeInsetsMake(0,-4,0.0, 0.0)];
        }
        image =  backImg;
        [button setImage: [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, titleWidth+image.size.width+8, 43);
        
    }else{
        button.frame = CGRectMake(0, 0, titleSize.width, 43);
        
    }
    
    button.titleLabel.textAlignment=NSTextAlignmentLeft;
    [button setTitle:title forState:UIControlStateNormal];
    if (title.length == 0 && !isShow) {
        
    }else{
        [button addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    }
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
}


-(void)loadNetData{
    
}

- (void)leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (CGFloat)cellContentViewWith{
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    // 适配ios7横屏
    if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
        width = [UIScreen mainScreen].bounds.size.height;
    }
    return width;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
